/*
 * Copyright (c) 2018 Hitevision
 */

package tw.com.hitevision.whiteboard.android.state;

import android.content.Context;
import android.util.Log;

import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.core.content.ContextCompat;
import tw.com.hitevision.whiteboard.android.R;
import tw.com.hitevision.whiteboard.android.display.DisplayDpiHelper;
import tw.com.hitevision.whiteboard.android.render.Word;

public class WordProperty {
    public static final float MAX_SIZE = 180.0f;
    public static final float MIN_SIZE = 30.0f;
//    public static final float SIZE_INCREMENT = 30.0f;
    public static final float SIZE_INCREMENT = 10.0f;
//    public static final float DEFAULT_SIZE = 60.0f;
    public static final float DEFAULT_SIZE = 40.0f;

    private float size;
    private TextColor textColor;

    public WordProperty() {
        size = DEFAULT_SIZE;
        textColor = TextColor.WHITE;
    }

    public WordProperty(TextColor textColor, float size){
        this.size = size;
        this.textColor = textColor;
    }

    public void setColor(TextColor c) {
        textColor = c;
    }

    public TextColor getColor() {
        return textColor;
    }

    public void setSize(float s) {
        size = s;
    }

    public float getSize() {
        return size;
    }

    public Word createText(Context context, float x, float y) {
        @ColorInt int color = ContextCompat.getColor(context, getColorRes());
        float factor = DisplayDpiHelper.getInstance().getFake4kFactor();
        Log.d("TAG", "createText: " + factor);
        Word word = new Word(context, x, y, color, size * factor);
        return word;
    }

    @ColorRes
    public int getColorRes() {
        switch (textColor) {
            case BLACK:
                return R.color.pen_black;
            case WHITE:
                return R.color.pen_white;
            case RED:
                return R.color.pen_red;
            case YELLOW:
                return R.color.pen_pure_yellow;
            case GREEN:
                return R.color.pen_green;
            case BLUE:
                return R.color.pen_blue;
            case YELLOW_SOFT:
                return R.color.pen_soft_yellow;
            case GREEN_SOFT:
                return R.color.pen_soft_green;
            case BLUE_SOFT:
                return R.color.pen_soft_blue;
            case PURPLE:
                return R.color.pen_purple;
            case PINK:
                return R.color.pen_pink;
            case VERMILION:
                return R.color.pen_vermilion;
            case ORANGE:
                return R.color.pen_orange;
            default:
                return 0;
        }
    }

    public enum TextColor {
        BLACK, WHITE, RED, YELLOW, GREEN, BLUE, PURPLE, PINK, VERMILION, ORANGE,BLUE_SOFT,GREEN_SOFT,YELLOW_SOFT
    }
}
